﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LitJson;
using System.IO;
using System.Text;

/// <summary>
/// 
/// </summary>
public class ItemDataManager 
{
    private static ItemDataManager instance;
    public static ItemDataManager Instance
    {
        get
        {
            if (instance == null) instance = new ItemDataManager();
            return instance;
        }
    }
    private JsonData itemdata;
    private List<ItemBase> deatbase = new List<ItemBase>();

	public void Init ()
    {
        //itemdata = JsonMapper.ToObject(File.ReadAllText(Application.dataPath + "/itembase/items.json", Encoding.GetEncoding("GB2312")));
        itemdata = JsonMapper.ToObject(File.ReadAllText(Application.dataPath + "/Config/BackPackItems.json", Encoding.GetEncoding("GB2312")));
        ConstructItemDatabase();
        
	}
	

    void ConstructItemDatabase()
    {
        //for (int i = 0; i < itemdata.Count; i++)
        //{
        //    deatbase.Add(new Item((int)itemdata[i]["id"], itemdata[i]["name"].ToString(),
        //        (int)itemdata[i]["value"], itemdata[i]["describe"].ToString(), itemdata[i]["madeby"].ToString()));
        //}
        for (int i = 0; i < itemdata.Count; i++)
        {
            int id =  (int)itemdata[i]["ItemID"];
            string itemName = itemdata[i]["ItemName"].ToString();
            string itemDesc = itemdata[i]["ItemDesc"].ToString();
            int itemType = (int)itemdata[i]["ItemType"];
            string itemIcon = itemdata[i]["ItemIcon"].ToString();
            string itemBgIcon = itemdata[i]["ItemBgIcon"].ToString();
            int itemCount = (int)itemdata[i]["ItemCount"];
            int itemQuality = (int)itemdata[i]["ItemQuality"];
            int itemOpreation = (int)itemdata[i]["ItemOpreation"];

            Debug.LogError("id " + id + " itemName " + itemName + " itemDesc " + itemDesc + " itemType " +
                itemType + " itemIcon " + itemIcon + " itemBgIcon  " + itemBgIcon + " itemCount " + itemCount +
                " itemQuality " + itemQuality + " itemOpreation " + itemOpreation);
        }
    }

}

